package com.yykj.hospital.server.handler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.yykj.hospital.server.dto.HospitalLabelImportDTO;
import org.springframework.util.StringUtils;

/**
 * Created by chendg
 * on 2021/10/31 0031.
 */

public class HospitalLabelHandler implements IExcelVerifyHandler<HospitalLabelImportDTO> {
    private Integer rowNum = 1;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(HospitalLabelImportDTO dto) {
        StringBuilder sb = new StringBuilder();
        boolean flag = true;

        if (StringUtils.isEmpty(dto.getName())  ) {
            flag = false;
            sb.append("标签名称不能为空 ");
        }
        if(dto.getSorting() == null){
            dto.setSorting(0);
        }

        dto.setRowNum(rowNum++);
        dto.setErrorMsg(sb.toString());

        if (flag) {
            return new ExcelVerifyHandlerResult(true, null);
        } else {
            return new ExcelVerifyHandlerResult(false, sb.toString());
        }
    }
}
